import request from '@/utils/request'
import { IAllMenuTreeResponse, IRoleListResponse } from './type'
import { IResponseBase } from '../type'

export const reqRoleList = (page, limit, roleName?: string) =>
  request.get<any, IRoleListResponse>(
    `/admin/acl/role/${page}/${limit}?${roleName == undefined ? '' : 'roleName=' + roleName}`,
  )

export const reqUpdateRole = (param) => {
  if (!param.id) {
    return request.post<any, IResponseBase>('/admin/acl/role/save', param)
  } else {
    return request.put<any, IResponseBase>('/admin/acl/role/update', param)
  }
}

export const reqAllMenuTree = (roleId: string) =>
  request.get<any, IAllMenuTreeResponse>(
    `/admin/acl/permission/toAssign/${roleId}`,
  )
export const reqDoAssign = (roleId, permissionId) =>
  request.post(
    '/admin/acl/permission/doAssign?roleId=' +
      roleId +
      '&permissionId=' +
      permissionId,
  )

export const reqDeleteRole = (id: string) =>
  request.delete<any, IResponseBase>(`/admin/acl/user/remove/${id}`)
